/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.TaskManager;
/*     */ import com.newcrm.exception.DBException;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.util.Date;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class AddTask extends AbstractAction
/*     */ {
/*  26 */   private static Logger logger = Logger.getLogger(AddTask.class.getName());
/*     */ 
/*     */   public AddTask(AbstractHttpServlet servlet) {
/*  29 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  35 */     String taskTitle = Util.getURLParameter(request
/*  36 */       .getParameter("TaskTitle"));
/*     */ 
/*  38 */     String strDueDate = request.getParameter("DueDate");
/*  39 */     Date dueDate = null;
/*  40 */     if ((strDueDate != null) && (strDueDate.contains(":")))
/*  41 */       dueDate = Util.str2Date2(strDueDate);
/*     */     else {
/*  43 */       dueDate = Util.str2Date(strDueDate);
/*     */     }
/*     */ 
/*  46 */     String responsibleUserId = Util.getURLParameter(request
/*  47 */       .getParameter("ResponsibleUserId"));
/*  48 */     int categoryId = Util.getURLIntParameter(request
/*  49 */       .getParameter("CategoryId"));
/*  50 */     int taskVisible = Util.getURLIntParameter(request
/*  51 */       .getParameter("TaskVisible"));
/*  52 */     String referenceUrl = Util.getURLParameter(request
/*  53 */       .getParameter("ReferenceUrl"));
/*  54 */     String referenceTitle = Util.getURLParameter(request
/*  55 */       .getParameter("ReferenceTitle"));
/*  56 */     int referenceId = Util.getURLIntParameter(request
/*  57 */       .getParameter("ReferenceId"));
/*  58 */     int referenceType = Util.getURLIntParameter(request
/*  59 */       .getParameter("ReferenceType"));
/*     */ 
/*  61 */     User loginUser = getLoginUser(request);
/*  62 */     int companyId = loginUser.companyId;
/*  63 */     String userId = loginUser.userId;
/*     */ 
/*  65 */     response.setContentType("text/html;charset=utf-8");
/*  66 */     PrintWriter out = response.getWriter();
/*  67 */     JSONObject jsonObject = new JSONObject();
/*     */ 
/*  69 */     if (responsibleUserId == null) {
/*  70 */       responsibleUserId = userId;
/*     */     }
/*     */ 
/*  74 */     if ((taskTitle == null) || (taskTitle.trim().length() == 0)) {
/*  75 */       logger.warn("taskTitle is null");
/*  76 */       jsonObject.put("error", "1");
/*  77 */       jsonObject.put("msg", "创建任务的过程中发现错误，请稍后再试");
/*  78 */       out.println(jsonObject);
/*  79 */       out.flush();
/*  80 */       out.close();
/*  81 */       return;
/*     */     }
/*     */ 
/*  84 */     TaskManager manager = new TaskManager();
/*     */     try {
/*  86 */       int taskId = manager.add(taskTitle, dueDate, responsibleUserId, 
/*  87 */         categoryId, taskVisible, referenceUrl, referenceTitle, 
/*  88 */         companyId, referenceId, referenceType, userId);
/*  89 */       if (taskId > 0) {
/*  90 */         jsonObject.put("error", "0");
/*  91 */         jsonObject.put("taskId", Integer.valueOf(taskId));
/*     */       } else {
/*  93 */         jsonObject.put("error", "1");
/*  94 */         jsonObject.put("msg", "创建任务的过程中发现错误，请稍后再试");
/*     */       }
/*     */     } catch (DBException e) {
/*  97 */       logger.warn("add task failed", e);
/*  98 */       jsonObject.put("error", "1");
/*  99 */       jsonObject.put("msg", "创建任务的过程中发现错误，请稍后再试");
/*     */     }
/* 101 */     out.println(jsonObject);
/* 102 */     out.flush();
/* 103 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.AddTask
 * JD-Core Version:    0.6.1
 */